package dominion.model.actions.base;

import java.util.ArrayList;
import java.util.List;

import dominion.model.Card;
import dominion.model.GameBoard;
import dominion.model.Player;
import dominion.model.actions.Action;
import dominion.model.monies.Coin;
import dominion.utils.Constants;

public class Adventurer extends Action {

	public Adventurer() {
		cost = 6;
	}

	@Override
	public Card clone() {
		return new Adventurer();
	}

	@Override
	public String toString() {
		return "Adventurer";
	}

	@Override
	public String getDescription() {
		StringBuffer sb = new StringBuffer();
		sb.append(super.getDescription());
		sb.append("Reveal cards from your deck until you reveal 2 Treasure cards.\n");
		sb.append("Put those Treasure cards in your hand and discard the other revealed cards.\n");
		return sb.toString();
	}

	@Override
	public void doAction(Player player, GameBoard board, List<Player> players) {
		player.changeAction(-1);

		int treasureCount = 0;
		List<Card> revealed = new ArrayList<Card>();
		while (treasureCount < 2)
		{
			Card card = player.drawTopCardFromDeck(Constants.LIBRARY_DECK);
			revealed.add(card);
			if (card instanceof Coin)
			{
				treasureCount++;
				player.addToDeck(card, Constants.HAND);
			}
		}

		Constants.printer.print("Cards revealed from Adventurer: ");
		for (Card current : revealed)
		{
			Constants.printer.print("|" + current + "|");
			if (!(current instanceof Coin))
			{
				player.addToDeck(current, Constants.DISCARD_DECK);
			}
		}

		playedCard(player);
		Constants.printer.print("New Hand: ");
		Constants.printer.print(player.printHand());
	}
}
